#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>
#include <QGridLayout>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //创建四个按钮
    QPushButton * p1 = new QPushButton("1");
    QPushButton * p2 = new QPushButton("2");
    QPushButton * p3 = new QPushButton("3");
    QPushButton * p4 = new QPushButton("4");
    QPushButton * p5 = new QPushButton("5");
    QPushButton * p6 = new QPushButton("6");
    //创建一个网格布局
    QGridLayout * glayout = new QGridLayout();
    this->setLayout(glayout);
    //将按钮排成3*2
    glayout->addWidget(p1,0,0);
    glayout->addWidget(p2,1,0);
    glayout->addWidget(p3,2,0);
    glayout->addWidget(p4,0,1);
    glayout->addWidget(p5,1,1);
    glayout->addWidget(p6,2,1);
    //设置按钮的尺寸
    p1->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    p2->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    p3->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    p4->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    p5->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    p6->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);

    //水平放置
//    glayout->addWidget(p1,0,0);
//    glayout->addWidget(p2,0,1);
//    glayout->addWidget(p3,0,2);
//    glayout->addWidget(p4,0,3);
    //网格放置
//    glayout->addWidget(p1,0,0);
//    glayout->addWidget(p2,0,1);
//    glayout->addWidget(p3,1,0);
//    glayout->addWidget(p4,1,1);
    //垂直放置
//    glayout->addWidget(p1,0,0);
//    glayout->addWidget(p2,1,0);
//    glayout->addWidget(p3,2,0);
//    glayout->addWidget(p4,3,0);
//    glayout->addWidget(p1,0,1);
//    glayout->addWidget(p2,0,2);
//    glayout->addWidget(p3,0,3);
//    glayout->addWidget(p4,1,1);
//    glayout->addWidget(p5,1,2);
//    glayout->addWidget(p6,1,3);

//    glayout->setColumnStretch(1,1);
//    glayout->setColumnStretch(2,2);
//    glayout->setColumnStretch(3,3);

}

Widget::~Widget()
{
    delete ui;
}

